package rex.xmla;
import junit.framework.TestCase;
import junit.framework.Assert;
import junit.framework.TestSuite;
import junit.framework.Test;
import junit.framework.AssertionFailedError;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import rex.xmla.XMLAObjectsFactory;
import rex.xmla.XMLADiscoverRestrictions;
import rex.xmla.XMLADiscoverProperties;
import rex.xmla.XMLAExecuteProperties;
import org.w3c.dom.Document;
import rex.metadata.SAXMemberHandler;
import rex.metadata.resultelements.Cell;
import rex.graphics.datasourcetree.elements.DataSourceElement;
import rex.graphics.datasourcetree.elements.CatalogElement;
import rex.graphics.datasourcetree.elements.CubeElement;
import rex.graphics.dimensiontree.elements.DimensionElement;
import rex.graphics.dimensiontree.elements.DimensionTreeElement;
import rex.graphics.dimensiontree.elements.HierarchyElement;
import rex.graphics.dimensiontree.elements.LevelElement;
import rex.graphics.dimensiontree.elements.MeasureElement;
import rex.graphics.dimensiontree.elements.MemberElement;
public class RexXMLAPortTest extends TestCase {
RexXMLAPort port1,port2;
String mdxQuerySales,mdxQueryInv;
URL url1;
XMLAExecuteProperties execPropFoodMart;
XMLAExecuteProperties execPropInventory;
XMLADiscoverProperties prop;
XMLADiscoverRestrictions rest;
public static void main(String[] args) {
//junit.swingui.TestRunner.run(RexXMLAPortTest.class);
junit.textui.TestRunner.run(suite());
}
public static Test suite()
{
return new TestSuite(RexXMLAPortTest.class);
}
protected void setUp() throws Exception {
super.setUp();
mdxQuerySales="SELECT NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS, NON EMPTY {[Time].[1997]} ON ROWS FROM [Sales]";
mdxQueryInv="SELECT NON EMPTY {[Measures].[nQuantity]} ON COLUMNS, NON EMPTY {[Time].[2006]} ON ROWS FROM [Inventory]";
url1=new URL("http://localhost:8080/mondrian/xmla.jsp");
port1 = new RexXMLAPort(url1);
execPropFoodMart= XMLAObjectsFactory.newXMLAExecuteProperties();
execPropInventory= XMLAObjectsFactory.newXMLAExecuteProperties();
prop= XMLAObjectsFactory.newXMLADiscoverProperties();
rest= XMLAObjectsFactory.newXMLADiscoverRestrictions();
execPropFoodMart.setDataSourceInfo("FoodMartSource");
execPropFoodMart.setCatalog("FoodMart");
execPropInventory.setDataSourceInfo("InventorySource");
execPropInventory.setCatalog("Inventory");
// url2=new URL("http://localhost:8080/mondrian/xmla.jsp");
//port1=new RexXMLAPort(url1);
//port2=new RexXMLAPort(url2);
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
mdxQuerySales="";
mdxQueryInv="";
}
/**
* Constructor for RexXMLAPortTest.
* @param arg0
*/
public RexXMLAPortTest(String arg0) {
super(arg0);
}
public void testRexXMLAPort() {
//TODO Implement RexXMLAPort().
}
public void testXmlEncodeString() {
//TODO Implement xmlEncodeString().
}
public void testExecute() {
try
{
// Result of following Query should be 266773.
// SELECT NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS, NON EMPTY {[Time].[1997]} ON ROWS FROM [Sales]
Assert.assertEquals("266773",(new Cell((((port1.execute(mdxQuerySales,execPropFoodMart)).getElementsByTagName("CellData")).item(0).getChildNodes()).item(1))).getCellValue());
// Result of following Query should be 66984555.
// SELECT NON EMPTY {[Measures].[nQuantity]} ON COLUMNS, NON EMPTY {[Time].[2006]} ON ROWS FROM [Inventory]
Assert.assertEquals("66984555",(new Cell((((port1.execute(mdxQueryInv,execPropInventory)).getElementsByTagName("CellData")).item(0).getChildNodes()).item(1))).getCellValue());
}
catch(Exception exc)
{
System.out.println("From TestExecute Exception");
System.out.println("Exception Error"+exc.getMessage());
System.out.println("Exception Error in String : "+exc.toString());
}
}
public void testDiscoverDataSources() {
try
{
Assert.assertEquals("InventorySource",(new DataSourceElement(null,(((port1.discoverDataSources(rest,prop)).getElementsByTagName("row")).item(0)))).getDataSourceName());
Assert.assertEquals("FoodMartSource",(new DataSourceElement(null,(((port1.discoverDataSources(rest,prop)).getElementsByTagName("row")).item(1)))).getDataSourceName());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetCatalogList() {
try
{
prop.setDataSourceInfo("InventorySource");
Assert.assertEquals("Inventory",(new CatalogElement(null,(((port1.getCatalogList(rest,prop)).getElementsByTagName("row")).item(0)),null)).toString());
prop.setDataSourceInfo("FoodMartSource");
Assert.assertEquals("FoodMart",(new CatalogElement(null,(((port1.getCatalogList(rest,prop)).getElementsByTagName("row")).item(0)),null)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetCubeList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
Assert.assertEquals("Inventory",(new CubeElement(null,(((port1.getCubeList(rest,prop)).getElementsByTagName("row")).item(1)),null)).toString());
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
Assert.assertEquals("Sales",(new CubeElement(null,(((port1.getCubeList(rest,prop)).getElementsByTagName("row")).item(0)),null)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetDimensionList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCubeName("Inventory");
Assert.assertEquals("Measures",(new DimensionElement(null,(((port1.getDimensionList(rest,prop)).getElementsByTagName("row")).item(0)),null,null)).toString());
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
rest.setCubeName("Sales");
Assert.assertEquals("Measures",(new DimensionElement(null,(((port1.getDimensionList(rest,prop)).getElementsByTagName("row")).item(0)),null,null)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetHierarchyList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCubeName("Inventory");
//Time is the Second level Hierarchy in Inventory Cube
Assert.assertEquals("Time",(new DimensionElement(null,(((port1.getDimensionList(rest,prop)).getElementsByTagName("row")).item(1)),null,null)).toString());
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
rest.setCubeName("Sales");
//Store is the Second level Hierarchy in Inventory Cube
Assert.assertEquals("Store",(new DimensionElement(null,(((port1.getDimensionList(rest,prop)).getElementsByTagName("row")).item(1)),null,null)).toString());
//System.out.println("From Test Hierarchy list method : "+(new HierarchyElement(null,(((port1.getHierarchyList(rest,prop)).getElementsByTagName("row")).item(1)),null,null)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetLevelList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCatalog("Inventory");
rest.setCubeName("Inventory");
//Week is the Third level in Time Dimension in Inventory Cube
Assert.assertEquals("Week",(new LevelElement(null,(((port1.getLevelList(rest,prop)).getElementsByTagName("row")).item(3)),rest,prop)).toString());
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
rest.setCatalog("FoodMart");
rest.setCubeName("Sales");
//"Store State" is the Third level in Store Dimension in Inventory Cube
Assert.assertEquals("Store State",(new LevelElement(null,(((port1.getLevelList(rest,prop)).getElementsByTagName("row")).item(3)),rest,prop)).toString());
//System.out.println("From Test Level list method : "+(new LevelElement(null,(((port1.getLevelList(rest,prop)).getElementsByTagName("row")).item(3)),rest,prop)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
public void testGetMeasureList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCubeName("Inventory");
//"nQuantity" is the First Measure in Inventory Cube
Assert.assertEquals("nQuantity",(new MeasureElement(null,(((port1.getMeasureList(rest,prop)).getElementsByTagName("row")).item(0)),rest,prop)).toString());
//System.out.println("From Test Meausure list : "+(new MeasureElement(null,(((port1.getMeasureList(rest,prop)).getElementsByTagName("row")).item(0)),rest,prop)).toString());
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
rest.setCubeName("Sales");
//"Unit Sales" is the First Measure in Sales Cube
Assert.assertEquals("Unit Sales",(new MeasureElement(null,(((port1.getMeasureList(rest,prop)).getElementsByTagName("row")).item(0)),rest,prop)).toString());
//System.out.println("From Test Meausure list : "+(new MeasureElement(null,(((port1.getMeasureList(rest,prop)).getElementsByTagName("row")).item(0)),rest,prop)).toString());
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
/*
public void testGetMemberList() {
try
{
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCubeName("Inventory");
//Assert.assertEquals(port1.getMemberList(rest,prop),port2.getMemberList(rest,prop));
//System.out.println("From Test Member list : "+(new MemberElement(null,(((port1.getMemberList(rest,prop)).getElementsByTagName("row")).item(1)),null,null)).toString());
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXMemberHandler handler = new SAXMemberHandler(null, rest, prop, false);
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(port1.getMemberListAsStream(rest, prop) , handler);
DimensionTreeElement[] retVal=handler.getMembers();
for(int abc=0;abc<retVal.length;abc++)
System.out.println("From Test Member list : "+retVal[abc].toString());
//prop.setDataSourceInfo("FoodMartSource");
//prop.setCatalog("FoodMart");
//rest.setCubeName("Sales");
//Assert.assertEquals(port1.getMemberList(rest,prop),port2.getMemberList(rest,prop));
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
System.out.println(exc.getMessage());
System.out.println(exc.toString());
}
}
public void testGetMemberListAsStream() {
try
{
XMLADiscoverProperties prop= XMLAObjectsFactory.newXMLADiscoverProperties();
XMLADiscoverRestrictions rest= XMLAObjectsFactory.newXMLADiscoverRestrictions();
port1 = new RexXMLAPort(url1);
port2 = new RexXMLAPort(url2);
prop.setDataSourceInfo("InventorySource");
prop.setCatalog("Inventory");
rest.setCubeName("Inventory");
Assert.assertEquals(port1.getMemberListAsStream(rest,prop),port2.getMemberListAsStream(rest,prop));
prop.setDataSourceInfo("FoodMartSource");
prop.setCatalog("FoodMart");
rest.setCubeName("Sales");
Assert.assertEquals(port1.getMemberListAsStream(rest,prop),port2.getMemberListAsStream(rest,prop));
}
catch(Exception exc)
{
System.out.println("Error"+exc.getStackTrace());
}
}
*/
}